package oracle.apps.financials.collection.adapter;

import oracle.apps.financials.collection.po.Customer;
import oracle.apps.financials.collection.widget.PagedAdapter;

import org.achartengine.GraphicalView;
import org.achartengine.tools.LineSliderListener;
import org.achartengine.tools.TimeSliderRangeListener;

import android.content.Context;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.cyrilmottier.android.greendroid.R;

public abstract class BaseChartAdapter extends PagedAdapter {
	
	public static final String TAG = BaseChartAdapter.class.getSimpleName();

	protected Customer customer;
	protected Context context;
	protected double xMin, xMax, currentX;

	protected GraphicalView lineChart;
	protected GraphicalView timeSliderChart;
	protected GraphicalView pieChart;
	protected ViewGroup graphViewGroup;

	protected LinearLayout lineChartLayout;
	protected LinearLayout pieChartLayout;
	protected LinearLayout timeSliderLayout;

	protected TimeSliderRangeListener mOnRangeChangeListner;
	protected LineSliderListener lineSliderListener;
	protected XYChartTimeRangeAnimator timeRangeAnimator = new XYChartTimeRangeAnimator();

	public BaseChartAdapter(Context context, Customer customer, ViewGroup graphViewGroup) {
		this.context = context;
		this.customer = customer;
		this.graphViewGroup = graphViewGroup;

	}
	
	
	
	

	public void initGraphView(ViewGroup graphViewGroup) {

		lineChartLayout = (LinearLayout) graphViewGroup.findViewById(R.id.line_chart);
		timeSliderLayout = (LinearLayout) graphViewGroup.findViewById(R.id.time_slider_chart);
		pieChartLayout = (LinearLayout) graphViewGroup.findViewById(R.id.pie_chart);

		this.lineChart = getLineChart();
		this.timeSliderChart = getTimeSlideChart();
		this.pieChart = getPieChart();

		if (lineChartLayout != null && lineChart != null) {
			lineChartLayout.removeAllViews();
			lineChartLayout.addView(lineChart);
		} else {
			Log.d(TAG, "lineChartLayout=" + lineChart + " " + "lineChart=" + lineChart);
		}
		if (timeSliderLayout != null && timeSliderChart != null) {
			timeSliderLayout.removeAllViews();
			timeSliderLayout.addView(timeSliderChart);
		} else {
			Log.d(TAG, "timeSliderLayout=" + timeSliderLayout + " " + "timeSliderChart=" + timeSliderChart);
		}
		if (pieChartLayout != null && pieChart != null) {
			pieChartLayout.removeAllViews();
			pieChartLayout.addView(pieChart);
		} else {
			Log.d(TAG, "pieChartLayout=" + pieChartLayout + " " + "pieChart=" + pieChart);
		}

	}

	public void setXAxisRange(GraphicalView mView, double start, double end) {
		xMax = end;
		xMin = start;
		timeRangeAnimator.start(mView, start, end);
	}

	public GraphicalView getLineChart() {
		return null;
	}

	public GraphicalView getTimeSlideChart() {
		return null;
	}

	public GraphicalView getPieChart() {
		return null;
	}

	public void refreshData(Customer customer) {
		this.customer = customer;
		this.notifyDataSetChanged();
	}

	public abstract void notifyDataSetChanged();

	public Customer getCustomer() {
		return customer;
	}

	public void setCustomer(Customer customer) {
		this.customer = customer;
	}

	public Context getContext() {
		return context;
	}

	public void setContext(Context context) {
		this.context = context;
	}

	@Override
	public int getCount() {
		return 2;
	}

	@Override
	public Object getItem(int position) {
		return null;
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		return null;
	}

}